#region Usings
using System;
using System.Reflection;

using Lib.Data.ORM.Entity;
using Lib.Data.ORM.EntityManagement;
using Lib.Utils.ObjUtils.ToStringConverters;
using Lib.Utils.RandomGenerators;
#endregion

namespace BK.BaseEntities
{
    public class BaseBkEntity : BaseEntity<IdentifierInt>, ICloneable
    {
        #region Instance Properties
        [MappedKey(IsIdentity = true, ValuePropertyName = "Value")]
        public override IdentifierInt Id
        {
            get { return base.Id; }
        }
        #endregion

        #region Instance Methods
        public override string ToString()
        {
            return ToStringConverter.ConvertClass(this);
        }

        public void FillWithRandomValues()
        {
            Random random = new Random();

            StringRandomGenerator stringRandomGenerator = new StringRandomGenerator();
            PropertyInfo[] propertyInfos = GetType().GetProperties();
            foreach (PropertyInfo propertyInfo in propertyInfos)
            {
                if (propertyInfo.PropertyType == typeof(string))
                {
                    propertyInfo.SetValue(this, stringRandomGenerator.Generate(), null);
                }

                if (propertyInfo.PropertyType == typeof(int?))
                {
                    int next = random.Next(1, 1000000);
                    propertyInfo.SetValue(this, next, null);
                }
            }
        }
        #endregion

        #region ICloneable Members
        public object Clone()
        {
            throw new NotImplementedException();
        }
        #endregion
    }
}